class Post < ActiveRecord::Base
  validates :author, :title, :content, :admin_user_id, presence: true
  validates :author ,
            length: {minimum: 2,maximum: 16}
  validates :title,
            length: {minimum: 2,maximum: 50}
  validates :content,
            length: {minimum: 1,maximum: 16000}
  resourcify

  #我属于谁
  belongs_to :admin_user, :class_name => 'Admin::User',
             inverse_of: :posts,
             counter_cache: true    #对象总数缓存，需要手动在主键一方创建posts_count
  belongs_to :blog_sort,     #手动创建外键blog_sort_id
             inverse_of: :posts,
             counter_cache: true

end
